<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>实时干扰告警查询</title>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
     
    function postExcelFile(params, url) { //params是post请求需要的参数，url是请求url地址
	    var form = document.createElement("form");
	    form.style.display = 'none';
	    form.action = url;
	    form.method = "post";
	    document.body.appendChild(form);

	    for(var key in params){
	      var input = document.createElement("input");
	      input.type = "hidden";
	      input.name = key;
	      input.value = params[key];
	      form.appendChild(input);
	    }

	    form.submit();
	    form.remove();
	  }
	function exportInterferenceInCurrentPage(){
		var rows  = $('#dg').datagrid("getRows");
		if (rows.length < 1) {
			$.messager.alert("系统提示", "请查询需要导出的数据");
			return;
		}
    	var params = {data:JSON.stringify(rows)};
    	postExcelFile(params, "${pageContext.request.contextPath}/interferencequery/exportcurrentpageQuery.do");
	}
    
    function exportInterferenceInAllPages(){
    	var startTime=$("#i1").datebox("getValue");
		var endTime=$("#i2").datebox("getValue");
		var startTimeLong = new Date(startTime.replace(new RegExp("-","gm"),"/")).getTime();
		var endTimeLong = new Date(endTime.replace(new RegExp("-","gm"),"/")).getTime();
		var frontId=$("#frontId").combobox("getText");
		var interference_type=$("#interference_type").combobox("getText");
		var disposed=$("#isDisposed").combobox("getText");
		window.open('${pageContext.request.contextPath}/interferencequery/exportQuery.do?frontId='+frontId+'&interference_type='+interference_type+'&startTime='+startTimeLong+'&endTime='+endTimeLong+'&disposed='+disposed+'&isHistory='+0);
    }
    
	function searchInterference(){
		//checkTimeValidity();
		var startTime=$("#i1").datebox("getValue");
		var endTime=$("#i2").datebox("getValue");
		var startTimeLong = new Date(startTime.replace(new RegExp("-","gm"),"/")).getTime();
		var endTimeLong = new Date(endTime.replace(new RegExp("-","gm"),"/")).getTime();
		 if(startTimeLong-endTimeLong>=0){
			 $.messager.alert("系统提示","查询开始时间"+startTime+"不能大于结束时间"+endTime+"！");
			 return;
		 }
		 $("#dg").datagrid('load',{
			"frontId":$("#frontId").combobox("getText"),
			"interference_type":$("#interference_type").combobox("getText"),
		 	"startTime":startTimeLong,
		 	"endTime":endTimeLong,
		 	"disposed":$("#isDisposed").combobox("getText"),
		 	"releaseWay":"",
		 	"isHistory":"0"
		 });
	}
	$(function(){
		$('#i1').datetimebox('setValue', formatterDate(new Date(new Date(new Date().toLocaleDateString()).getTime())));
		$('#i2').datetimebox('setValue', formatterDate(new Date()));
		$('#isDisposed').combotree('setValue', 2);
		searchInterference();
	});
	
	formatterDate = function (date) {
    	var day = date.getDate();
    	var month = (date.getMonth() + 1);
    	var hor = date.getHours();
    	var min = date.getMinutes();
    	var sec = date.getSeconds();
    	return date.getFullYear() + '-' + month + '-' + day+" "+hor+":"+min+":"+sec;
    };
	
    function checkinfmeasurement(){
    	var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择一条要编辑的数据！");
			 return;
		 }
		var row=selectedRows[0];
		var FrontId = row.frontId;
		var TimeBegin = row.timeBegin;
		var TimeEnd = row.timeEnd;
		var InfType=row.infSourceType;
		if(InfType=='BCCH同频干扰'){	
			if (parent.$('#tabs').tabs('exists', "干扰测量报告查询")) {
				 parent.$('#tabs').tabs('close', "干扰测量报告查询")
				 var url="/page_interference/InfMeasurement.jsp?FrontId="+FrontId+"&TimeBegin="+TimeBegin+"&TimeEnd="+TimeEnd;
				 parent.openTab("干扰测量报告查询",encodeURI(url));
			 } 
			 else {
				 var url="/page_interference/InfMeasurement.jsp?FrontId="+FrontId+"&TimeBegin="+TimeBegin+"&TimeEnd="+TimeEnd;
				parent.openTab("干扰测量报告查询",encodeURI(url));
			 }
			
		}
		else{
			$.messager.alert("系统提示","当前记录没有测量报告，请选择正确的记录！");
		}
    }
    
    function checkspectrum(){
    	var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择一条要编辑的数据！");
			 return;
		 }
		var row=selectedRows[0];
		var FrontId = row.BSName;
		var TimeBegin = row.timeBegin;
		var TimeEnd = row.timeEnd;
		var Direction=row.direction;
		var InfChannel=row.infChannel;
		var InfType=row.infType;
		var InfIntensity=row.infIntensity;
		var TCH;
		var BCCH;
		$.post("${pageContext.request.contextPath}/interferencequery/gettch.do",{frontId:FrontId},function(result){
		 TCH=result.TCH;
		 BCCH= result.BCCH;
		 if (parent.$('#tabs').tabs('exists', "干扰频谱查询")) {
			 parent.$('#tabs').tabs('close', "干扰频谱查询")
			 var url="/page_interference/InfSpectrum.jsp?FrontId="+FrontId+"&TimeBegin="+TimeBegin+"&TimeEnd="+TimeEnd+"&Direction="+Direction+"&InfType="+InfType+"&InfChannel="+InfChannel+"&InfIntensity="+InfIntensity+"&TCH="+TCH+"&BCCH="+BCCH; 
			 parent.openTab("干扰频谱查询",encodeURI(url));
		 } 
		 else {
			 var url="/page_interference/InfSpectrum.jsp?FrontId="+FrontId+"&TimeBegin="+TimeBegin+"&TimeEnd="+TimeEnd+"&Direction="+Direction+"&InfType="+InfType+"&InfChannel="+InfChannel+"&InfIntensity="+InfIntensity+"&TCH="+TCH+"&BCCH="+BCCH;
			 parent.openTab("干扰频谱查询",encodeURI(url));
		 }
			},"json");
	    
    }
    
    function formatInfIntensity(value) {
		if (value.length < 5) return value;
		return parseFloat(value).toFixed(2);
	}
    
    function markHandled() {
		var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length==0){
			 $.messager.alert("系统提示","请选择要标记的数据！");
			 return;
		 }
		 var frontIds=[];
		 var directions=[];
		 var infChannels=[];
		 var intTypes=[];
		 for(var i=0;i<selectedRows.length;i++){
			 if(selectedRows[i].disposed=='是'){
				 $.messager.alert("系统提示","当前选择的数据中包含已处理的数据，请重新选择！");
				 return;
			 }
			 frontIds.push(selectedRows[i].frontId);
			 directions.push(selectedRows[i].direction);
			 if(selectedRows[i].infChannel==''||selectedRows[i].infChannel==null){
				 infChannels.push(0);
			 }
			 else
				 infChannels.push(selectedRows[i].infChannel);
			 intTypes.push(selectedRows[i].infType);
		 }
		 var FIDs=frontIds.join(";");
		 var DIRs=directions.join(";");
		 var INFCs=infChannels.join(";");
		 var INTS=intTypes.join(";");
		 var isDisposed=1;
		 $.messager.confirm("系统提示","您确定要标记这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
				if(r){
					$.post("${pageContext.request.contextPath}/interferencequery/changeinterference.do",{FIDs:FIDs,DIRs:DIRs,INFCs:INFCs,INTS:INTS},function(result){
						if(result.success){
							 $.messager.alert("系统提示","已标记成功！");
							 searchInterference();
						}else{
							$.messager.alert("系统提示","标记失败，请联系系统管理员！");
						}
					},"json");
				} 
			 });
	}
    
</script>
</head>
<body style="margin: 1px">
	
<table id="dg" title="实时干扰告警查询" class="easyui-datagrid"
   fitColumns="fasle" pagination="true" rownumbers="true" pageSize="100" pageList="[100,200,300,400,500]"
   url="${pageContext.request.contextPath}/interferencequery/list.do" fit="true" toolbar="#tb">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<th field="alarmLevel" width="80" align="center">告警级别</th>
   		<th field="frontId" width="80" align="center">前置机号</th>
   		<th field="BSName" width="120" align="center">基站</th>
   		<th field="timeBegin" width="160" align="center">开始时间</th>
   		<th field="timeEnd" width="160" align="center">结束时间</th>
   		<th field="direction" width="70" align="center">上下行</th>
   		<th field="engineID" width="80" align="center">机车号</th>
   		<th field="kilometer" width="80" align="center">公里标</th>
   		<th field="infIntensity" width="100" align="center" formatter="formatInfIntensity">干扰强度</th>
   		<th field="infBandWidth" width="80" align="center">干扰带宽</th>
   		<th field="infProbability" width="80" align="center">被干扰概率</th>
   		<th field="infChannel" width="70" align="center">干扰频道</th>
   		<th field="infMaxChannel" width="70" align="center">最强干扰频道</th>
   		<th field="infSecChannel" width="70" align="center">次强干扰频道</th>
   		<th field="infType" width="140" align="center">干扰类型</th>
   		<th field="infSourceType" width="120" align="center">干扰源类型</th>
   		<th field="disposed" width="80" align="center">是否已处理</th>
   		<th field="releaseWay" width="80" align="center">告警解除方式</th>
   		<th field="releaseTime" width="160" align="center">告警解除时间</th>
   	</tr>
   </thead>
 </table>
 <div id="tb">
    <div>&nbsp;&nbsp;
    	<a href="javascript:exportInterferenceInCurrentPage()" class="easyui-linkbutton" iconCls="icon-save" plain="false">导出当前页干扰记录</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 		<a href="javascript:exportInterferenceInAllPages()" class="easyui-linkbutton" iconCls="icon-save" plain="false">导出所有页干扰记录</a>
    </div>
    <br>
    <div>
 		&nbsp;&nbsp;&nbsp;小区：&nbsp;
 		<input class="easyui-combotree" id="frontId" name="frontId"  style="width:140px" data-options="panelHeight:'auto', panelMaxHeight:'240px',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/frontId.do'" multiple/>   
 		&nbsp;&nbsp;&nbsp;干扰类型：&nbsp;
 		<input class="easyui-combotree" id="interference_type" name="interference_type" data-options="panelHeight:'auto', panelMaxHeight:'240px',valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/interferencequery/interferencelist.do'" multiple/>          
 		&nbsp;&nbsp;&nbsp;时间：&nbsp;<input type="text" id="i1" size="20" class="easyui-datetimebox" style="width:150px" />&nbsp;至&nbsp;
		<input type="text" id="i2" size="20" class="easyui-datetimebox"  style="width:150px" />
		&nbsp;&nbsp;&nbsp;是否已处理：&nbsp;<input class="easyui-combotree" id="isDisposed" 
					    data-options="panelHeight:'auto', panelMaxHeight:'240px',valueField:'lable',textField:'value',
					    data:[{id:'1000', text:'全选', children: [{id: 1, text: '是'},{id: 2, text: '否'}]}]"
					    style="text-align:center;width: 90px" editable="false" multiple/>
 		&nbsp;&nbsp;&nbsp;&nbsp;
 		<a href="javascript:searchInterference()" class="easyui-linkbutton" iconCls="icon-search" plain="false"><b style="font-size:15px">搜索</b></a>
 	</div>
 	
 	<div>&nbsp;&nbsp;
 	        <a href="javascript:checkspectrum()" class="easyui-linkbutton" iconCls="icon-edit" plain="false">查看频谱图</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 		    <a href="javascript:checkinfmeasurement()" class="easyui-linkbutton" iconCls="icon-edit" plain="false">查看测量报告</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 		    <c:if test="${currentMemberShip.group.name=='管理员' }">
 		    <a href="javascript:markHandled()" class="easyui-linkbutton" iconCls="icon-ok" plain="false">标记为已处理</a>
 		      <!-- <a href="javascript:markUnHandled()" class="easyui-linkbutton" iconCls="icon-check" plain="true">标记为未处理</a> -->
 		    </c:if>
 	</div>
 	<br>
 </div>
	
</body>
</html>